home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 2 / Macwelt DVD 2.cdr / System / Internet-Utilities / macosx / News Mac 1.1.dmg / StringUtil.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-04-08  |  2.7 KB  |  100 lines

  1. public class StringUtil {
  2.    public static String[] sortString(String[] items) {
  3.       for(int c = 0; c < items.length; ++c) {
  4.          for(int i = 0; i < items.length - 1; ++i) {
  5.             if (items[i].compareTo(items[i + 1]) > 0) {
  6.                String temp = items[i];
  7.                items[i] = items[i + 1];
  8.                items[i + 1] = temp;
  9.             }
  10.          }
  11.       }
  12.  
  13.       return items;
  14.    }
  15.  
  16.    public static boolean contains(String source, String match) throws Exception {
  17.       if (source.length() < match.length()) {
  18.          throw new Exception("String to match is longer than source! (" + source + " < " + match + ")");
  19.       } else {
  20.          try {
  21.             for(int i = 0; i < source.length() - match.length() + 1; ++i) {
  22.                if (source.substring(i, i + match.length()).equalsIgnoreCase(match)) {
  23.                   return true;
  24.                }
  25.             }
  26.  
  27.             return false;
  28.          } catch (Exception var3) {
  29.             throw new Exception("Error searching for " + match + " in " + source + "\n" + var3);
  30.          }
  31.       }
  32.    }
  33.  
  34.    public static int positionOf(String source, String subString) throws Exception {
  35.       if (source.length() < subString.length()) {
  36.          throw new Exception("Sub string is longer than source! (" + source + " < " + subString + ")");
  37.       } else {
  38.          try {
  39.             for(int i = 0; i < source.length() - subString.length() + 1; ++i) {
  40.                if (source.substring(i, i + subString.length()).equals(subString)) {
  41.                   return i;
  42.                }
  43.             }
  44.  
  45.             return -1;
  46.          } catch (Exception var3) {
  47.             throw new Exception("Error searching for " + subString + " in " + source + "\n" + var3);
  48.          }
  49.       }
  50.    }
  51.  
  52.    public static String getFileName(String filePath) throws Exception {
  53.       try {
  54.          for(int i = filePath.length() - 1; i > 0; --i) {
  55.             if (filePath.charAt(i) == '/') {
  56.                return filePath.substring(i + 1, filePath.length());
  57.             }
  58.          }
  59.  
  60.          return null;
  61.       } catch (Exception var2) {
  62.          throw new Exception("Error getting path from " + filePath + "\n" + var2);
  63.       }
  64.    }
  65.  
  66.    public static String getPath(String filePath) throws Exception {
  67.       try {
  68.          for(int i = filePath.length() - 1; i > 0; --i) {
  69.             if (filePath.charAt(i) == '/') {
  70.                return filePath.substring(0, i);
  71.             }
  72.          }
  73.  
  74.          return null;
  75.       } catch (Exception var2) {
  76.          throw new Exception("Error getting path from " + filePath + "\n" + var2);
  77.       }
  78.    }
  79.  
  80.    public static String getExtension(String filePath) throws Exception {
  81.       try {
  82.          for(int i = filePath.length() - 1; i > 0; --i) {
  83.             if (filePath.charAt(i) == '.') {
  84.                return filePath.substring(i, filePath.length());
  85.             }
  86.          }
  87.  
  88.          return null;
  89.       } catch (Exception var2) {
  90.          throw new Exception("Error getting path from " + filePath + "\n" + var2);
  91.       }
  92.    }
  93.  
  94.    public static String toLowerCase(String theString) {
  95.       String temp = "";
  96.       temp = theString.toLowerCase();
  97.       return temp;
  98.    }
  99. }
  100.